clear all
macro drop _all

* program:	LSQ_gini_replication.do
* 			Estimation of regression models.
* paper:	The Unequal Distribution of Speaking Time within Parliamentary Party Groups
* authors:	Hanna Bäck, Markus Baumann, Marc Debus & Jochen Müller
* date:		September 2018


* Preparation
ssc install estout // if not yet installed
net install grc1leg, from(http://www.stata.com/users/vwiggins)
ssc install blindschemes

global folder = "C:\...\LSQ_gini_replication"
* ... should refer to the folder where the .dta files can be found.

 
* TABLE 2:
use "$folder\LSQ_gini_data_table2.dta", clear

eststo T2m1: xtmixed gini_words_ppg_period_adj ///
	i.end_of_term_B ib10.parfam ib276.country ///
	governing_B MP_total ///
		|| ppg: end_of_term_B
		 
eststo T2m2: xtmixed gini_speeches_ppg_period_adj ///
	i.end_of_term_B ib10.parfam ib276.country ///
	governing_B MP_total ///
		|| ppg: end_of_term_B 

eststo T2m3: xtmixed gini_debates_ppg_period_adj ///
	i.end_of_term_B ib10.parfam ib276.country ///
	governing_B MP_total ///
		|| ppg: end_of_term_B 

esttab T2m1 T2m2 T2m3 ///
	, mtitles("WORDS" "SPEECHES" "PARTICIPATIONS") ///
		label ///
		starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
		title("") ///
		note("") ///
		aic compress
		
		
* TABLE 3
eststo clear
foreach dura in "90" "180" "270" "360" {
	use "$folder\LSQ_gini_data_table3_`dura'days.dta", clear
	
	eststo ML7_per`dura': xtmixed gini_words_ppg_period_pol_adj ///
		i.end_of_term_B##c.C_CMP_grouped_rank ///
		 governing_B MP_total words_total ///
		 ib10.parfam ///
			|| ppg: end_of_term_B || CMP_grouped: end_of_term_B

	margins end_of_term_B, at(C_CMP_grouped_rank=(-5.8 (0.25) 6.18))
	marginsplot, ///
		plot2opts(lcolor(gs9)) ///
		recastci(rarea) recast(line) name(Margins_`dura', replace) ///
		title("Election proximity: `dura' days") ///
		xtitle("") ytitle("") ///
		yscale(range(.5 1)) ylab(.5(.1)1) ///
		legend(order(3 "early in term" 4 "late in term") rows(1)) ///
			scheme(plotplain) nodraw
}	

grc1leg  Margins_90 Margins_180 Margins_270 Margins_360, pos(6)

esttab ML7_per90  ML7_per180 ML7_per270 ML7_per360 ///
	, mtitles("90" "180" "270" "360") ///
		label ///
		starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
		title("") ///
		note("") ///
		aic compress
